/*************************************************************************
  > File Name: ChainOfResponsibility.cc
  > Author: Joker
  > Mail: mahongtao@foxmail.com 
  > Created Time: 2020-09-22 12:37:08
 ************************************************************************/

#include "ChainOfResponsibility.h"

#include <iostream>

using std::cout;
using std::endl;

Handler::Handler(Handler * pSuccessor)
    :_pSuccessor(pSuccessor)
{
    cout << "Handler(Handler *)" << endl;
}

Handler::~Handler(){
    cout << "~Handler()" << endl;

    delete _pSuccessor;
    _pSuccessor = nullptr;
}

void ConcreateHandler1::HandleRequest(){
    if(nullptr != _pSuccessor){
        _pSuccessor->HandleRequest();
    }
    else{
        cout << "HandleRequest by ConcreateHandler1" << endl;
    }
}

void ConcreateHandler2::HandleRequest(){
    if(nullptr != _pSuccessor){
        _pSuccessor->HandleRequest();
    }
    else{
        cout << "HandleRequest by ConcreateHandler2" << endl;
    }
}
